package com.lvyq.javaprint;

import com.lvyq.javaprint.constant.ImgConstant;
import com.lvyq.javaprint.constant.TrayConstant;
import com.lvyq.javaprint.util.PDFPrintUtils;
import com.lvyq.javaprint.util.PrintUtils;
import com.lvyq.javaprint.util.StageUtils;
import com.lvyq.javaprint.view.tray.TrayMainView;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;

/**
 * @author lvyq
 * @version 1.0
 * Create by 2024-04-24 15:46
 */
public class MainWinApplication extends Application {

    @Override
    public void start(Stage primaryStage)  {

        System.setProperty("java.awt.headless", "false");
        Platform.setImplicitExit(false);

        // 创建文本标签
        Label label = new Label(PrintUtils.defaultPrintService());
        StackPane root = new StackPane();
        root.getChildren().add(label);
        Scene scene = new Scene(root, 200, 100);
        primaryStage.setTitle(TrayConstant.APP_TITLE);
        primaryStage.setScene(scene);
        primaryStage.setHeight(100);
        primaryStage.setWidth(200);
        Image icon = new Image(ImgConstant.ICON_URL);
        primaryStage.getIcons().add(icon);



        //屏幕右小角
        StageUtils.rightBottomWindow(primaryStage);

        primaryStage.setOnCloseRequest(windowEvent -> {
            //创建托盘
            if (SystemTray.isSupported()){
                TrayMainView.createTray(primaryStage);
            }
            primaryStage.hide(); // 隐藏窗口
        });

        primaryStage.show();

    }

}
